package org.hrqing.chess.entity.mapper;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.UUID;

/**
 * @author Hrqing
 */
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public abstract class BaseEntity {

    private String id;

    @JsonIgnore
    public boolean isNew() {
        return this.id == null || this.id.trim().isEmpty();
    }

    @JsonIgnore
    public void prePersist() {
        if (isNew()) {
            this.id = UUID.randomUUID().toString();
        }
    }
}
